import request from '@/utils/request'

// 查询抄录入列表
export function listNyCheckMeter(query) {
  return request({
    url: '/energy/nyCheckMeter/list',
    method: 'get',
    params: query
  })
}

// 查询抄录入详细
export function getNyCheckMeter(id) {
  return request({
    url: '/energy/nyCheckMeter/' + id,
    method: 'get'
  })
}

// 新增抄录入
export function addNyCheckMeter(data) {
  return request({
    url: '/energy/nyCheckMeter',
    method: 'post',
    data: data
  })
}

// 修改抄录入
export function updateNyCheckMeter(data) {
  return request({
    url: '/energy/nyCheckMeter',
    method: 'put',
    data: data
  })
}

// 删除抄录入
export function delNyCheckMeter(id) {
  return request({
    url: '/energy/nyCheckMeter/' + id,
    method: 'delete'
  })
}

// 下载导入模板
export function importTemplate() {
  return request({
    url: '/energy/nyCheckMeter/importTemplate',
    method: 'get'
  })
}

// 下载抄表记录
export function downloadCheckMeter1(url,params,filename) {
  return request({
    url:url,
    method:'get',
    params:params,
    responseType: 'blob'
  }).then((data) => {
    const content = data
    const blob = new Blob([content])
    if ('download' in document.createElement('a')) {
      const elink = document.createElement('a')
      elink.download = filename
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(blob)
      document.body.appendChild(elink)
      elink.click()
      URL.revokeObjectURL(elink.href)
      document.body.removeChild(elink)
    } else {
      navigator.msSaveBlob(blob, filename)
    }
  }).catch((r) => {
    console.error(r)
  })
}

// 计算私表汇总及差额
export function getCompute(id) {
  return request({
    url: '/energy/nyCheckMeter/compute/' + id,
    method: 'get'
  }).catch((r) => {
    console.error(r)
  })
}

// 计算私汇总列表
export function computePlus(query) {
  return request({
    url: '/energy/nyCheckMeter/list2',
    method: 'get',
    params: query
  })
}

// 计算私汇总列表
export function computePlus1(query) {
  return request({
    url: '/energy/nyCheckMeter/result',
    method: 'get',
    params: query
  })
}
// 新增抄录入
// export function addNyCheckMeter(data) {
//   return request({
//     url: '/energy/nyCheckMeter',
//     method: 'post',
//     data: data
//   })
// }

// 查询私汇总列表
export function listNyCheckSum(query) {
  return request({
    url: '/energy/nyCheckSum/list',
    method: 'get',
    params: query
  })
}

// 查询私汇总详细
export function getNyCheckSum(id) {
  return request({
    url: '/energy/nyCheckSum/' + id,
    method: 'get'
  })
}

// 新增私汇总
export function addNyCheckSums(data) {
  return request({
    url: '/energy/nyCheckSum/logs',
    method: 'post',
    data: data
  })
}

// 删除私汇总
export function delNyCheckSum(id) {
  return request({
    url: '/energy/nyCheckSum/' + id,
    method: 'delete'
  })
}

